using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace SLING
{
    class Form
    {

        public Form()
        {
        }

        public void FileOpen()
        {
            //Simulate a file selected by the user to open
            ArrayList lines = new ArrayList();
            lines.Add("; Add two (32-Bit) numbers");
            lines.Add("  ");
            lines.Add(" TTL	Ch4Ex3 - add");
            lines.Add(" AREA	Program, CODE, READONLY	");
            lines.Add(" ENTRY");
            lines.Add(" ");
            lines.Add("Main");
            lines.Add(" LDR	R1,Value1		; Load the first number");
            lines.Add(" LDR	R2,Value2		; Load the second number");
            lines.Add(" ADD	R1,R1,R2		; ADD them together into R1 (x = x + y)");
            lines.Add(" STR	R1,Result		; Store the result");
            lines.Add(" SWI	&11");
            lines.Add("");
            lines.Add("Value1	DCD	&37E3C123		; First value to be added");
            lines.Add("Value2	DCD	&367402AA		; Second value to be added");
            lines.Add("Result	DCD	0			; Storage for result");
            lines.Add("");
            lines.Add(" END");
            //Output - result should store 6e57c3cd

            Manager.GetInstance().LoadFile(lines);
        }

        public void Go()
        {
            Console.WriteLine("Start");
            Manager.GetInstance().Run();

            Console.WriteLine("Final Status of Registers and memory");
            Console.WriteLine("R1:" + Manager.GetInstance().CPU.Registers[1].ToString("X"));
            Console.WriteLine("R2:" + Manager.GetInstance().CPU.Registers[2].ToString("X"));
            Console.WriteLine("R3:" + Manager.GetInstance().CPU.Registers[3].ToString("X"));            
            Console.WriteLine("Memory Count:" + Manager.GetInstance().CPU.Memory.Count);
            Console.WriteLine("Memory Contents:");
            foreach (KeyValuePair<string, UInt32> mem in Manager.GetInstance().CPU.Memory)
            {
                Console.WriteLine("Label: " + mem.Key + " Value: " + mem.Value.ToString("X"));
            }

        }

        public void Step()
        {
            Manager.GetInstance().Step();
        }
    }
}
